package cn.edu.scau.cmi.mazhuanglong.comprehensive;

import java.text.NumberFormat;

import javax.swing.table.AbstractTableModel;

public class ScoreTableModel extends AbstractTableModel {
	Object[] columnNames2 = { "成绩区段", "人数", "百分比" };
	Object[][] rowData = new Object[6][3];
	double[] Score = new double[30];
	int[] n = new int[5];

	public ScoreTableModel() {
		for (int i = 0; i < 30; i++) {
			Score[i] = new Double(teacherInterface.table.getValueAt(i, 4).toString());
			if (Score[i] < 60)
				n[4]++;
			if (Score[i] >= 60 && Score[i] < 70)
				n[3]++;
			if (Score[i] >= 70 && Score[i] < 80)
				n[2]++;
			if (Score[i] >= 80 && Score[i] < 90)
				n[1]++;
			if (Score[i] >= 90 && Score[i] <= 100)
				n[0]++;
		}
		NumberFormat nf = NumberFormat.getNumberInstance();
		nf.setMaximumFractionDigits(2);
		for (int i = 0; i < 6; i++) {
			switch (i) {
			case 0:
				rowData[i][0] = "成绩区段";
				rowData[i][1] = "人数";
				rowData[i][2] = "百分比";
				break;
			case 1:
				rowData[i][0] = "90-100";
				rowData[i][1] = n[i - 1];
				rowData[i][2] = nf.format((double) n[i - 1] / 30);
				break;
			case 2:
				rowData[i][0] = "80-89";
				rowData[i][1] = n[i - 1];
				rowData[i][2] = nf.format((double) n[i - 1] / 30);
				break;
			case 3:
				rowData[i][0] = "70-79";
				rowData[i][1] = n[i - 1];
				rowData[i][2] = nf.format((double) n[i - 1] / 30);
				break;
			case 4:
				rowData[i][0] = "60-69";
				rowData[i][1] = n[i - 1];
				rowData[i][2] = nf.format((double) n[i - 1] / 30);
				break;
			case 5:
				rowData[i][0] = "0-59";
				rowData[i][1] = n[i - 1];
				rowData[i][2] = nf.format((double) n[i - 1] / 30);
				break;
			}
		}
	}

	public String getColumnName(int column) {
		return columnNames2[column].toString();
	}

	@Override
	public int getColumnCount() {// 获取列数
		// TODO Auto-generated method stub
		return columnNames2.length;
	}

	@Override
	public int getRowCount() {// 获取行数
		// TODO Auto-generated method stub
		return rowData.length;
	}

	@Override
	public Object getValueAt(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return rowData[arg0][arg1];
	}

}
